package tree;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Stack;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class levelOrderBottom {
    List<List<Integer>> result = new ArrayList<>();
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        dfs(root, 0);
        Collections.reverse(result);
        return result;
    }
    public void dfs(TreeNode node, Integer deep){
        if (node == null){
            return;
        }
        deep++;
        if (result.size() < deep){
            ArrayList<Integer> item = new ArrayList<>();
            result.add(item);
        }
        result.get(deep-1).add(node.val);
        dfs(node.left, deep);
        dfs(node.right, deep);
    }
}
